
Class('viewmanager', 'linb.Com',{
    Instance:{
        //base Class for this com
        base:["linb.UI"], 
        //requried class for this com
        required:["linb.UI.Dialog", "linb.UI.Image", "linb.UI.Pane", "linb.UI.TreeGrid", "linb.UI.Label", "linb.UI.Input", "linb.UI.CheckBox", "linb.UI.ComboInput", "linb.UI.Button", "linb.UI.Block"], 
        parents: null, 
        vmself:null, 
        sobj:"", 
        properties:{}, 
        events:{}, 
        iniResource:function(com, threadid){
        }, 
        iniComponents:function(){
            // [[code created by jsLinb UI Builder
            var host=this, children=[], append=function(child){children.push(child.get(0))};
            
            append((new linb.UI.Dialog)
                .host(host,"dlg_history_view")
                .setLeft(50)
                .setTop(20)
                .setWidth(940)
                .setHeight(519)
                .setResizer(false)
                .setCaption("历史状态显示")
                .setMinBtn(false)
                .setMaxBtn(false)
                .onRender("_dlg_history_view_onrender")
                .beforeDestroy("_dlg_history_view_beforedestroy")
            );
            
            host.dlg_history_view.append((new linb.UI.Pane)
                .host(host,"pane6")
                .setDock("left")
                .setWidth(290)
            );
            
            host.pane6.append((new linb.UI.Pane)
                .host(host,"pane18")
                .setDock("top")
                .setHeight(50)
            );
            
            host.pane18.append((new linb.UI.Label)
                .host(host,"label1")
                .setLeft(0)
                .setTop(20)
                .setWidth(70)
                .setCaption("搜索IP地址")
            );
            
            host.pane18.append((new linb.UI.Input)
                .host(host,"searchip")
                .setLeft(80)
                .setTop(20)
                .setWidth(110)
            );
            
            host.pane18.append((new linb.UI.Button)
                .host(host,"btnsearch")
                .setLeft(200)
                .setTop(20)
                .setWidth(80)
                .setCaption("搜索")
                .onClick("_button8_onclick")
            );
            
            host.pane6.append((new linb.UI.TreeGrid)
                .host(host,"treegrid2")
                .setHeader([{"id":"id", "width":10, "type":"label", "caption":"ID"}, {"id":"ip", "width":100, "type":"label", "caption":"设备IP"}, {"id":"dtype", "width":120, "caption":"设备类型", "type":"label"}, {"id":"descri", "width":120, "caption":"设备类型", "type":"label"}])
                .setRows([{"cells":[{"value":1}, {"value":1234}, {"value":3}, {"value":4}], "id":"b"}])
                .onRowSelected("_treegrid2_onrowselected")
            );
            
            host.dlg_history_view.append((new linb.UI.Pane)
                .host(host,"pane7")
                .setDock("fill")
            );
            
            host.pane7.append((new linb.UI.Pane)
                .host(host,"pane65")
                .setDock("bottom")
                .setHeight(198)
                .setVisibility("visible")
            );
            
            host.pane65.append((new linb.UI.Image)
                .host(host,"image3")
                .setDock("center")
                .setLeft(150)
                .setTop(0)
                .setWidth(350)
                .setHeight(190)
            );
            
            host.pane65.append((new linb.UI.Button)
                .host(host,"btnSee")
                .setLeft(510)
                .setTop(160)
                .setCaption("查看详图")
                .onClick("_btnsee_onclick")
            );
            
            host.pane7.append((new linb.UI.Label)
                .host(host,"label2")
                .setLeft(30)
                .setTop(20)
                .setWidth(60)
                .setCaption("设备名称")
            );
            
            host.pane7.append((new linb.UI.Label)
                .host(host,"label3")
                .setLeft(30)
                .setTop(50)
                .setWidth(60)
                .setCaption("设备描述")
            );
            
            host.pane7.append((new linb.UI.Label)
                .host(host,"label4")
                .setLeft(30)
                .setTop(80)
                .setWidth(60)
                .setCaption("产品描述")
            );
            
            host.pane7.append((new linb.UI.Label)
                .host(host,"label5")
                .setLeft(320)
                .setTop(20)
                .setCaption("放置地点")
            );
            
            host.pane7.append((new linb.UI.Input)
                .host(host,"devicename")
                .setLeft(100)
                .setTop(20)
                .setWidth(270)
                .setReadonly(true)
            );
            
            host.pane7.append((new linb.UI.Input)
                .host(host,"devicelocation")
                .setLeft(450)
                .setTop(20)
                .setWidth(170)
                .setReadonly(true)
            );
            
            host.pane7.append((new linb.UI.Input)
                .host(host,"devicedescri")
                .setLeft(100)
                .setTop(50)
                .setWidth(520)
                .setReadonly(true)
            );
            
            host.pane7.append((new linb.UI.Input)
                .host(host,"productdescri")
                .setLeft(100)
                .setTop(80)
                .setWidth(520)
                .setReadonly(true)
            );
            
            host.pane7.append((new linb.UI.Label)
                .host(host,"label6")
                .setLeft(30)
                .setTop(110)
                .setWidth(60)
                .setCaption("资源")
            );
            
            host.pane7.append((new linb.UI.Label)
                .host(host,"label7")
                .setLeft(20)
                .setTop(140)
                .setWidth(70)
                .setCaption("资源描述")
            );
            
            host.pane7.append((new linb.UI.Block)
                .host(host,"resourceblock")
                .setTag("rrr")
                .setLeft(100)
                .setTop(140)
                .setWidth(520)
                .setHeight(90)
                .setBorderType("inset")
            );
            
            host.pane7.append((new linb.UI.Label)
                .host(host,"label8")
                .setLeft(10)
                .setTop(250)
                .setWidth(90)
                .setCaption("查询日期区间")
            );
            
            host.pane7.append((new linb.UI.Label)
                .host(host,"label9")
                .setLeft(280)
                .setTop(250)
                .setWidth(30)
                .setCaption("到")
            );
            
            host.pane7.append((new linb.UI.Button)
                .host(host,"btnview")
                .setLeft(510)
                .setTop(250)
                .setCaption("历史状态查询")
                .onClick("_btnview_onclick")
            );
            
            host.pane7.append((new linb.UI.ComboInput)
                .host(host,"begindate")
                .setLeft(100)
                .setTop(250)
                .setType("datepicker")
            );
            
            host.pane7.append((new linb.UI.ComboInput)
                .host(host,"enddate")
                .setLeft(310)
                .setTop(250)
                .setType("datepicker")
            );
            
            host.pane7.append((new linb.UI.ComboInput)
                .host(host,"begintime")
                .setLeft(230)
                .setTop(250)
                .setWidth(60)
                .setType("timepicker")
            );
            
            host.pane7.append((new linb.UI.ComboInput)
                .host(host,"endtime")
                .setLeft(440)
                .setTop(250)
                .setWidth(60)
                .setType("timepicker")
            );
            
            host.pane7.append((new linb.UI.ComboInput)
                .host(host,"deviceresources")
                .setLeft(100)
                .setTop(110)
                .setWidth(520)
                .setReadonly(true)
                .afterUIValueSet("_deviceresources_afteruivalueset")
            );
            
            return children;
            // ]]code created by jsLinb UI Builder
        }, 
        searchdeviceinfo:function() {
            this.id = 0;
            this.ip = '127.0.0.1';
            this.dtype = 0;
            this.index = 0;
        }, 
        searchobject:function() {
            this.titlename ='';
            this.ip = '127.0.0.1';
            this.deviceid = 0;
            this.resourceindex = 0;
            this.devicetype = 0;
            this.beginsecs = 0;
            this.beginm ="00:00";
            this.graphtype = [1];
            this.endsecs = 0;
            this.endm = "00:00";

        }, 
        iniExComs:function(com, hreadid){
        }, 
        _dlg_history_view_onrender:function (profile) {
            vmself = this;
            vmself.loaddevices("list","");
            vmself.treegrid2.showColumn("dtype",false);
            vmself.begintime.setValue("00:00");
            vmself.endtime.setValue("12:00");
            vmself.begindate.setValue(new Date());
            vmself.enddate.setValue(new Date());

        }, 
        _button8_onclick:function (profile, e, src, value) {
            vmself.loaddevices("search",vmself.searchip.getUIValue());
        }, 
        _treegrid2_onrowselected:function (profile, row) {
            vmself.$row = row;
            selected_row = new vmself.searchdeviceinfo();
            selected_row.id = row.cells[0].value;
            selected_row.ip = row.cells[1].value;
            selected_row.dtype = row.cells[2].value;
            vmself.loaddeviceinfo("ld",_.serialize(selected_row));

        }, 
        _btnview_onclick:function (profile, e, src, value) {
            if (vmself.$row != null) {
                oo = new vmself.searchobject();
                oo.titlename=vmself.devicename.getValue()+
                "("+vmself.devicedescri.getValue()+","+
                vmself.devicelocation.getValue()+")";
                oo.deviceid = vmself.$row.cells[0].value;
                oo.ip = vmself.$row.cells[1].value;
                oo.devicetype = vmself.$row.cells[2].value;
                oo.resourceindex = vmself.deviceresources.getUIValue();
                vmself.begindate.updateValue();
                oo.beginsecs = vmself.begindate.getUIValue();
                vmself.enddate.updateValue();
                oo.endsecs = vmself.enddate.getUIValue();
                vmself.begintime.updateValue();
                oo.beginm = vmself.begintime.getUIValue();
                vmself.endtime.updateValue();
                oo.endm = vmself.endtime.getUIValue();
                vmself.createchart("chartview",_.serialize(oo));
            }
        }, 
        _dlg_history_view_beforedestroy:function (profile) {            
            if (parents != null) {
                oo = _.unserialize(parents.menubar1.getTagVar());
                oo.mhistory_state = 0;
                parents.menubar1.setTagVar(_.serialize(oo));
            }
            return true;
        }, 
        setWhoisParent:function(myparents) {
            parents = myparents;
        }, 
        createchart:function(cmd,datas) {
            linb.request("/NetDM4Web/viewchart.do","cmd="+cmd+"&datas="+datas,
            function(rep, type){
                returanpkg = _.unserialize(rep);
                if (returanpkg.code == 0) {
                    chartobject = _.unserialize(returanpkg.datas);
                    vmself.image3.setSrc(chartobject.graphlist);
                }
                if (returanpkg.code < 0){
                    linb.UI.Dialog.alert('提示',returanpkg.messages);
                }

            },
            function() {
                linb.UI.Dialog.alert('提示','网络连接出现问题，无法获得数据，请稍候重试');
            });

        }, 
        loadresource:function(cmd,datas) {
            linb.request("/NetDM4Web/viewchart.do","cmd="+cmd+"&datas="+datas,
            function(rep, type){
                returanpkg = _.unserialize(rep);
                if (returanpkg.code == 0) {
                    vmself.resourceblock.setHtml(returanpkg.datas);
                }
                if (returanpkg.code < 0){
                    linb.UI.Dialog.alert('提示',returanpkg.messages);
                }

            },
            function() {
                linb.UI.Dialog.alert('提示','网络连接出现问题，无法获得数据，请稍候重试');
            });

        }, 

        loaddeviceinfo:function(cmd,datas) {
            linb.request("/NetDM4Web/viewchart.do","cmd="+cmd+"&datas="+datas,
            function(rep, type){
                returanpkg = _.unserialize(rep);
                if (returanpkg.code == 0) {
                    deviceinfo = _.unserialize(returanpkg.datas);
                    vmself.devicename.setValue(deviceinfo.name);
                    vmself.devicelocation.setValue(deviceinfo.location);
                    vmself.devicedescri.setValue(deviceinfo.descri);
                    vmself.productdescri.setValue(deviceinfo.product_desc);
                    vmself.deviceresources.setItems(deviceinfo.resourceslist);
                }
                if (returanpkg.code < 0){
                    linb.UI.Dialog.alert('提示',returanpkg.messages);
                }

            },
            function() {
                linb.UI.Dialog.alert('提示','网络连接出现问题，无法获得数据，请稍候重试');
            });

        }, 
        loaddevices:function(cmd,datas) {
            linb.request("/NetDM4Web/viewchart.do","cmd="+cmd+"&datas="+datas,
            function(rep, type){
                aa = _.unserialize(rep);
                if (aa.code == 0) {
                    vmself.treegrid2.setRows(_.unserialize(aa.datas));
                }
                if (aa.code < 0){
                    linb.UI.Dialog.alert('提示',aa.messages);
                }

            },
            function() {
                linb.UI.Dialog.alert('提示','网络连接出现问题，无法获得数据，请稍候重试');
            });

        }, 
        ajaxinneraction:function(cmd,datas,successmessagefun,failmessagefun) {
            oo = vmself.ajaxoutteraction(cmd,datas);
            if (oo.code == 0) {
                successfun;
            } else {
                if (failmessagefun == null) {
                    linb.UI.Dialog.alert('提示',oo.messages);
                } else {
                    failmessagefun;
                }
            }
        }, 
        _deviceresources_afteruivalueset:function (profile, oldValue, newValue) {
            if (vmself.$row != null) {
                oo = new vmself.searchdeviceinfo();
                oo.id = vmself.$row.cells[0].value;
                oo.ip = vmself.$row.cells[1].value;
                oo.dtype = vmself.$row.cells[2].value;
                oo.index = newValue;
                vmself.loadresource("lr",_.serialize(oo));
            }
        }, 
        _btnsee_onclick:function (profile, e, src, value) {
            if (vmself.image3.getSrc() != "") {
            	src = vmself.image3.getSrc();
				(((new linb.UI.Dialog)
                .setLeft(274)
                .setTop(66)
                .setWidth(685)
                .setHeight(474)
                .setPosition("relative")
                .setCaption("查看详图")
                .setMinBtn(false)
                .setMaxBtn(false)
                ).append((new linb.UI.Image)
                .setLeft(20)
                .setTop(10)
                .setWidth(640)
                .setHeight(420)
                .setSrc(src)
            	)).show(linb('body'),true);            
            } else {
               alert("还没有指定缩略图，不能查看详图");
            }
        }
    }
});